package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.ChangeClientLog;
import cn.wolfcode.crm.query.ChangeClientLogQueryObject;
import cn.wolfcode.crm.service.IChangeClientLogService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import cn.wolfcode.crm.util.PermissionName;
import com.alibaba.fastjson.JSON;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: crm
 * @description:
 * @author: Mr.chen
 * @create: 2018-07-07 22:06
 **/
@Controller
@RequestMapping("changeClientLog")
public class ChangeClientLogController {
    @Autowired
    private IChangeClientLogService service;

    @RequestMapping("")
    @PermissionName("主页")
    @RequiresPermissions("changeClientLog:index")
    public String index() {
        return "changeClientLog/list";
    }

    
    @RequestMapping("list")
    @ResponseBody
    @RequiresPermissions("changeClientLog:list")
    @PermissionName("客户日志数据")
    public PageResult list(ChangeClientLogQueryObject qo) {
        PageResult result = service.query(qo);
        System.out.println(JSON.toJSONString(result));
        return result;
    }

    @RequestMapping("save")
    @ResponseBody
    @RequiresPermissions("changeClientLog:save")
    @PermissionName("客户日志保存")
    public JsonResult save(ChangeClientLog entity) {
        JsonResult result = new JsonResult();
        try {
            service.save(entity);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("保存操作失败");
        }
        return result;
    }
}
